
<template>
    <uni-popup background-color="#fff"  ref="popRef" type="right">
        <fl-popupfilter bumphNoShow :notice="false" urgency @filter="filter" />
    </uni-popup>
    <view class="docCommonScroll">
        <fl-filterTabs @handleEmitChange="handleEmitChange" :statuss="statuss" :wait="wait" />
        <scroll-view @scrolltolower="scrolltolower" class="scroll-view" scroll-y>
            <uni-swipe-action v-if="list.length > 0">
                <uni-swipe-action-item v-for="(ele, index) in list" :key="index">
                    <view @tap="handleReading(ele)" class="scroll_item">
                        <view class="left_status">
                            <text :style="{ backgroundColor: back[ele.urgencyLevel] }" class="status_tips">{{
                                label[ele.urgencyLevel] }}</text>
                        </view>
                        <view class="right_content">
                            <view class="doc_title ellipsis">
                                {{ ele.bumphTitle }}
                            </view>
                            <view class="doc_date">
                                <text>{{ ele.sendUnit }}</text>
                                <text>{{ ele.sendDate }}</text>
                            </view>
                        </view>
                    </view>
                    <template v-slot:right>
                        <!-- <view class="wander" v-if="ele.sendStatus == 1" @tap="handleWander(ele)">流转</view>
                        <view class="ending" v-if="ele.sendStatus == 1" @tap="handleEnd(ele)">办结</view>
                        <view class="Reading" v-if="ele.sendStatus == 0" @tap="handleReading(ele)">阅办</view>
                        <view style="background: red;" class="Reading" v-if="ele.sendStatus == 3" @tap="handleRevoke(ele)">
                            撤销办结
                        </view> -->
                        <!-- <view class="wander look"  @tap="lookGw(ele)">查看</view> -->
                    </template>
                </uni-swipe-action-item>
            </uni-swipe-action>
            <fl-empty v-else />
            <view style="padding: 10rpx 0;">
                <view class="none" v-if="isFinish">没有更多了~</view>
                <view class="loadMore" v-if="isMore">正在加载...</view>
            </view>
        </scroll-view>
    </view>
</template> 
<script setup lang="ts">
import { getReceivdocList, revokeFinish, ending, innerIssuereadFlow } from '@/api/http'
import modal from '@/plugins/modal'
import { onLoad, onShow } from "@dcloudio/uni-app";
import { ref, nextTick, watch } from 'vue'
const props = defineProps(['users', 'isRead', 'bumphTitle'])
const label: any = {
    '1': '平急',
    '2': '加急',
    '3': '特急',
}
const back: any = {
    '1': '#0dbea8',
    '2': '#F9C457',
    '3': '#EE0A24',
}
const isFinish = ref(false)
const isMore = ref(false)
const list: any = ref([])
const popRef = ref()
const wait = ref(0)
const total = ref(0)
const innerIssueId = ref('')
const par: any = {
    pageNum: 1,
    pageSize: 10,
    bumphStatus: 1,
    sendStatus: 0,
}
const statuss = [
    { name: '公文待阅', type: 0 },
    { name: '阅办中', type: 1 },
    { name: '已否决', type: 2 },
    { name: '已办结', type: 3 },
]
onLoad(() => {
    // nextTick(() => {
    //     getList()
    // })
})
watch(() => props.users, async (e) => {
    if (e) {
        let arr = e.map(v => v.userId)
        await innerIssuereadFlow({ innerIssueId: innerIssueId.value, userIds: arr })
        modal.msgSuccess('操作成功')
        reset()
    }
}, { deep: true })

watch(() => props.isRead, (e) => {
    if (e) {
        reset()
    }
})

watch(() => props.bumphTitle, (newV) => {
    par.bumphTitle = newV
    nextTick(() => {
        reset()
    })
}, { immediate: true })




const reset = () => {
    par.pageNum = 1
    isFinish.value = false;
    isMore.value = false;
    total.value = 0;
    list.value = []
    getList()
}

// const handleRevoke = async (ele: any) => {
//     const res = await modal.confirm('是否撤销办结当前功能')
//     if (res) {
//         await revokeFinish({ innerIssueId: ele.innerIssueId })
//         modal.msgSuccess('操作成功')
//         reset()
//     }
// }
// const handleEnd = async (ele: any) => {
//     if (ele.unRead !== "") return modal.showToast('当前公文还有其他用户未阅办，不能办结！')
//     const resu = await modal.confirm('是否办结当前功能?')
//     if (!resu) return
//     const res = await ending({ innerIssueId: ele.innerIssueId })
//     reset()
//     modal.msgSuccess('操作成功')
// }
const getList = async () => {
    const res = await getReceivdocList(par)
    if (par.sendStatus == 0) {
        wait.value = res.total
    }
    total.value = res.total
    list.value = [...list.value, ...res.rows]
}
const handleEmitChange = (t: number, type: number) => {
    switch (t) {
        case 1:
            popRef.value.open();
            break;
        case 2:
            delete par.sendStatus
            reset()
            break;
        case 3:
            par.sendStatus = type
            reset()
            break;
    }

}
const scrolltolower = () => {
    if (par.pageNum * par.pageSize >= total.value) {
        isFinish.value = true
        isMore.value = false
        return
    }
    par.pageNum += 1
    isMore.value = true
    getList()
}
// const lookGw = (ele: any) => {
//     uni.navigateTo({ url: '/pages/docToReadDetail/index?id=' + ele.innerIssueId + '&type=2' })
// }
// 去流转
// const handleWander = (ele: any) => {
//     innerIssueId.value = ele.innerIssueId
//     uni.navigateTo({ url: '/pages/wanderReceive/index?type=1' })
// }
// 去阅办 传递一个参数区分一下
const handleReading = (ele: any) => {
    // 已否决 和已 办结的 要跳转到 查看页面
    if (ele.sendStatus == 2 || ele.sendStatus == 3) {
        return uni.navigateTo({ url: '/pages/docToReadDetail/noOperate?id=' + ele.innerIssueId + '&type=1' + '&sendStatus=' + ele.sendStatus })
    }
    uni.navigateTo({ url: '/pages/docToReadDetail/index?id=' + ele.innerIssueId + '&type=1' + '&sendStatus=' + ele.sendStatus })
}

const filter = (e: any) => {
    const { date, status, t, bumphNo } = e
    //取消
    if (t === 0) return popRef.value.close()
    //确定
    if (date !== "") {
        par['params[beginTime]'] = e.date[0]
        par['params[endTime]'] = e.date[1]
    } else {
        delete par['params[beginTime]']
        delete par['params[endTime]']
    }
    if (status != 0) {
        par.bumph_urgency_leve = status
    } else {
        delete par.urgencyLevel
    }
    par.bumphNo = bumphNo

    reset()
    popRef.value.close()
}

</script>


<style scoped lang="scss">
.scroll-view {
    flex: 1;
    height: 100%;
    overflow: hidden;
    background-color: #fff;

    .wander,
    .ending,
    .Reading {
        display: flex;
        align-items: center;
        width: 140rpx;
        height: 100%;
        justify-content: center;
        color: #fff;
        background-color: #0d80d7;
        font-size: 28rpx;
    }

    .look {
        background-color: #5ac725;
    }

    .ending {
        background-color: red;
    }

    .scroll_item {
        display: flex;
        width: 94%;
        margin: 0 auto;
        padding: 25rpx 0;
        min-height: 176rpx;
        // background-color: red;
        border-bottom: 2rpx solid #eeeeee;

        .left_status {
            width: 12%;

            .status_tips {
                color: #fff;
                font-size: 24rpx;
                padding: 2rpx 8rpx;
                border-radius: 9rpx;
            }
        }

        .right_content {
            flex: 1;

            .doc_title {
                font-size: 28rpx;
                color: #323233;
            }

            .doc_date {
                display: flex;
                justify-content: space-between;
                font-size: 28rpx;
                color: #999999;
                margin-top: 10rpx;
            }
        }
    }
}
</style>
